/**************************************************************
 *@ProjectName: blweibo
 *@FileName: User.java
 *@Date: 2011-5-30
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo.models;

import java.io.Serializable;

import org.json.JSONObject;

/**
 * The Class User.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-30
 */
public class User implements Serializable {
    
    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -5939113709154053834L;
    
    /** The uid. */
    private String uid = "";
    
    /** The username. */
    private String username = "";
    
    /** The province. */
    private String province = "";
    
    /** The city. */
    private String city = "";
    
    /** The aboutme. */
    private String aboutme = "";
    
    /** The blogaddress. */
    private String blogaddress = "";
    
    /** The face. */
    private String face = "";
    
    /** The mysite. */
    private String mysite = "";
    
    /** The gender. */
    private String gender = "";
    
    /** The fans_count. */
    private String fans_count = "0";
    
    /** The follow_count. */
    private String follow_count = "0";
    
    /** The topic_count. */
    private String topic_count = "0";
    
    /** The favourite_count. */
    private String favourite_count = "0";
    
    /** The dateline. */
    private String dateline = "0";
    
    /** The validate. */
    private String validate = "0";
    
    /** The topic. */
    private Topic topic;

    /**
     * Instantiates a new user.
     * 
     * @param js
     *            the js
     */
    public User(JSONObject js) {
        if (js == null) {
            return;
        }
        uid = js.optString("uid");
        username = js.optString("username");
        province = js.optString("province");
        city = js.optString("city");
        aboutme = js.optString("aboutme");
        blogaddress = js.optString("blogaddress");
        face = js.optString("face");
        mysite = js.optString("mysite");
        gender = js.optString("gender");
        fans_count = js.optString("fans_count");
        follow_count = js.optString("follow_count");
        int p = Integer.parseInt(follow_count);
        if (p > 2000) {
            follow_count = "2000";
        }
        topic_count = js.optString("topic_count");
        favourite_count = js.optString("favourite_count");
        dateline = js.optString("dateline");
        validate = js.optString("validate");
        topic = new Topic(js.optJSONObject("topic"));
    }

    /**
     * Instantiates a new user.
     */
    public User() {
    }

    /**
     * Gets the topic.
     * 
     * @return the topic
     */
    public Topic getTopic() {
        return topic;
    }

    /**
     * Sets the topic.
     * 
     * @param topic
     *            the new topic
     */
    public void setTopic(Topic topic) {
        this.topic = topic;
    }

    /**
     * Gets the uid.
     * 
     * @return the uid
     */
    public String getUid() {
        return uid;
    }

    /**
     * Sets the uid.
     * 
     * @param uid
     *            the new uid
     */
    public void setUid(String uid) {
        this.uid = uid;
    }

    /**
     * Gets the username.
     * 
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * Sets the username.
     * 
     * @param username
     *            the new username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * Gets the province.
     * 
     * @return the province
     */
    public String getProvince() {
        return province;
    }

    /**
     * Sets the province.
     * 
     * @param province
     *            the new province
     */
    public void setProvince(String province) {
        this.province = province;
    }

    /**
     * Gets the city.
     * 
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * Sets the city.
     * 
     * @param city
     *            the new city
     */
    public void setCity(String city) {
        this.city = city;
    }

    /**
     * Gets the aboutme.
     * 
     * @return the aboutme
     */
    public String getAboutme() {
        return aboutme;
    }

    /**
     * Sets the aboutme.
     * 
     * @param aboutme
     *            the new aboutme
     */
    public void setAboutme(String aboutme) {
        this.aboutme = aboutme;
    }

    /**
     * Gets the blogaddress.
     * 
     * @return the blogaddress
     */
    public String getBlogaddress() {
        return blogaddress;
    }

    /**
     * Sets the blogaddress.
     * 
     * @param blogaddress
     *            the new blogaddress
     */
    public void setBlogaddress(String blogaddress) {
        this.blogaddress = blogaddress;
    }

    /**
     * Gets the face.
     * 
     * @return the face
     */
    public String getFace() {
        return face;
    }

    /**
     * Sets the face.
     * 
     * @param face
     *            the new face
     */
    public void setFace(String face) {
        this.face = face;
    }

    /**
     * Gets the mysite.
     * 
     * @return the mysite
     */
    public String getMysite() {
        return mysite;
    }

    /**
     * Sets the mysite.
     * 
     * @param mysite
     *            the new mysite
     */
    public void setMysite(String mysite) {
        this.mysite = mysite;
    }

    /**
     * Gets the gender.
     * 
     * @return the gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * Sets the gender.
     * 
     * @param gender
     *            the new gender
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    /**
     * Gets the fans_count.
     * 
     * @return the fans_count
     */
    public String getFans_count() {
        return fans_count;
    }

    /**
     * Sets the fans_count.
     * 
     * @param fans_count
     *            the new fans_count
     */
    public void setFans_count(String fans_count) {
        this.fans_count = fans_count;
    }

    /**
     * Gets the follow_count.
     * 
     * @return the follow_count
     */
    public String getFollow_count() {
        return follow_count;
    }

    /**
     * Sets the follow_count.
     * 
     * @param follow_count
     *            the new follow_count
     */
    public void setFollow_count(String follow_count) {
        this.follow_count = follow_count;
    }

    /**
     * Gets the topic_count.
     * 
     * @return the topic_count
     */
    public String getTopic_count() {
        return topic_count;
    }

    /**
     * Sets the topic_count.
     * 
     * @param topic_count
     *            the new topic_count
     */
    public void setTopic_count(String topic_count) {
        this.topic_count = topic_count;
    }

    /**
     * Gets the favourite_count.
     * 
     * @return the favourite_count
     */
    public String getFavourite_count() {
        return favourite_count;
    }

    /**
     * Sets the favourite_count.
     * 
     * @param favourite_count
     *            the new favourite_count
     */
    public void setFavourite_count(String favourite_count) {
        this.favourite_count = favourite_count;
    }

    /**
     * Gets the dateline.
     * 
     * @return the dateline
     */
    public String getDateline() {
        return dateline;
    }

    /**
     * Sets the dateline.
     * 
     * @param dateline
     *            the new dateline
     */
    public void setDateline(String dateline) {
        this.dateline = dateline;
    }

    /**
     * Gets the validate.
     * 
     * @return the validate
     */
    public String getValidate() {
        return validate;
    }

    /**
     * Sets the validate.
     * 
     * @param validate
     *            the new validate
     */
    public void setValidate(String validate) {
        this.validate = validate;
    }

    /**
     * Gets the q.
     * 
     * @return the q
     */
    public boolean getQ() {
        return (Integer.parseInt(validate) & 0x8) == 8;
    }

    /**
     * Gets the v.
     * 
     * @return the v
     */
    public boolean getV() {
        return (Integer.parseInt(validate) & 0x4) == 4;
    }

    /**
     * Gets the hR.
     * 
     * @return the hR
     */
    public boolean getHR() {
        return (Integer.parseInt(validate) & 0x2) == 2;
    }

    /**
     * Gets the l.
     * 
     * @return the l
     */
    public boolean getL() {
        return (Integer.parseInt(validate) & 0x1) == 1;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "User [uid=" + uid + ", username=" + username + ", province=" + province + ", city=" + city
                + ", aboutme=" + aboutme + ", blogaddress=" + blogaddress + ", face=" + face + ", mysite=" + mysite
                + ", gender=" + gender + ", fans_count=" + fans_count + ", follow_count=" + follow_count
                + ", topic_count=" + topic_count + ", favourite_count=" + favourite_count + ", dateline=" + dateline
                + ", validate=" + validate + "]";
    }

    /**
     * To json string.
     * 
     * @return the string
     */
    public String toJSONString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("\"uid\"").append(":\"").append(uid).append("\",");
        sb.append("\"username\"").append(":\"").append(username).append("\",");
        sb.append("\"province\"").append(":\"").append(province).append("\",");
        sb.append("\"city\"").append(":\"").append(city).append("\",");
        sb.append("\"aboutme\"").append(":\"").append(aboutme).append("\",");
        sb.append("\"blogaddress\"").append(":\"").append(blogaddress).append("\",");
        sb.append("\"face\"").append(":\"").append(face).append("\",");
        sb.append("\"mysite\"").append(":\"").append(mysite).append("\",");
        sb.append("\"gender\"").append(":\"").append(gender).append("\",");
        sb.append("\"fans_count\"").append(":\"").append(fans_count).append("\",");
        sb.append("\"follow_count\"").append(":\"").append(follow_count).append("\",");
        sb.append("\"topic_count\"").append(":\"").append(topic_count).append("\",");
        sb.append("\"favourite_count\"").append(":\"").append(favourite_count).append("\",");
        sb.append("\"dateline\"").append(":\"").append(dateline).append("\",");
        sb.append("\"validate\"").append(":\"").append(validate);
        sb.append("\"}");
        return sb.toString();
    }

}
